﻿function CheckSession() {
    var session = "";
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/CheckSession",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "",
        async: false,
        success: function (n) {
            var data = n.d.split(';');
            session = data[0];
            if (session !== "") {
                setTimeout(function () {
                    window.location.href = "/";
                }, data[1]);
            }
        },
        error: function () { }
    });
    return session;
}
function filldropdown(id_dropdown, arrSelect) {
    $(id_dropdown).empty();
    var strOption = "";
    strOption += "<option value=''>Chọn</option>";
    if (arrSelect.length > 0) {
        $.each(arrSelect, function (key, value) {
            var id = "",
                text = "",
                stt = 0;
            $.each(value, function (keymap, valuemap) {
                if (stt === 0) {
                    id = valuemap;
                } else if (stt === 1) {
                    text = valuemap;
                }
                stt += 1;
            });
            strOption += "<option value='" + id + "'>" + text + "</option>";
        });
    }
    $(id_dropdown).html(strOption);
    $(id_dropdown).selectpicker("refresh");
}
function filldropdown_notdefaultvalue(id_dropdown, arrSelect) {
    $(id_dropdown).empty();
    var strOption = "";
    if (arrSelect.length > 0) {
        $.each(arrSelect, function (key, value) {
            var id = "",
                text = "",
                stt = 0;
            $.each(value, function (keymap, valuemap) {
                if (stt === 0) {
                    id = valuemap;
                } else if (stt === 1) {
                    text = valuemap;
                }
                stt += 1;
            });
            strOption += "<option value='" + id + "'>" + text + "</option>";
        });
    }
    $(id_dropdown).html(strOption);
    $(id_dropdown).selectpicker("refresh");
}
function SelectAllLoaiKhachHang() {
    var arr = [];
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/SelectAllLoaiKhachHang",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "",
        async: false,
        success: function (n) {
            if (n.d !== "") {
                if (n.d != null || n.d != undefined) {
                    arr = $.parseJSON(n.d);
                }
            }
        },
        error: function () { }
    });
    return arr;
}
function SelectAllLoaiVatTu() {
    var arr = [];
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/SelectAllLoaiVatTu",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "",
        async: false,
        success: function (n) {
            if (n.d !== "") {
                if (n.d != null || n.d != undefined) {
                    arr = $.parseJSON(n.d);
                }
            }
        },
        error: function () { }
    });
    return arr;
}
function SelectAllNhomVatTu(maloaivattu) {
    var arr = [];
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/SelectAllNhomVatTu",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "{'maloaivattu': '" + maloaivattu + "'}",
        async: false,
        success: function (n) {
            if (n.d !== "") {
                if (n.d != null || n.d != undefined) {
                    arr = $.parseJSON(n.d);
                }
            }
        },
        error: function () { }
    });
    return arr;
}
function SelectAllVatTu(manhomvatttu) {
    var arr = [];
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/SelectAllVatTu",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "{'manhomvatttu': '" + manhomvatttu + "'}",
        async: false,
        success: function (n) {
            if (n.d !== "") {
                if (n.d != null || n.d != undefined) {
                    arr = $.parseJSON(n.d);
                }
            }
        },
        error: function () { }
    });
    return arr;
}
function SelectDonViById(madonvi) {
    var arr = [];
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/SelectDonViById",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "{'madonvi': '" + madonvi + "'}",
        async: false,
        success: function (n) {
            if (n.d !== "") {
                if (n.d != null || n.d != undefined) {
                    arr = $.parseJSON(n.d);
                }
            }
        },
        error: function () { }
    });
    return arr;
}
function SelectAllThue() {
    var arr = [];
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/SelectAllThue",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "",
        async: false,
        success: function (n) {
            if (n.d !== "") {
                if (n.d != null || n.d != undefined) {
                    arr = $.parseJSON(n.d);
                }
            }
        },
        error: function () {
            bootbox.alert(MsError);
        }
    });
    return arr;
}
function SelectAllKho() {
    var arr = [];
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/SelectAllKho",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "",
        async: false,
        success: function (n) {
            if (n.d !== "") {
                if (n.d != null || n.d != undefined) {
                    arr = $.parseJSON(n.d);
                }
            }
        },
        error: function () { }
    });
    return arr;
}
function SelectAllNhaCungCap() {
    var arr = [];
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/SelectAllNhaCungCap",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "",
        async: false,
        success: function (n) {
            if (n.d !== "") {
                if (n.d != null || n.d != undefined) {
                    arr = $.parseJSON(n.d);
                }
            }
        },
        error: function () { }
    });
    return arr;
}
function SelectAllNguonGocXuatXu() {
    var arr = [];
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/SelectAllNguonGocXuatXu",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "",
        async: false,
        success: function (n) {
            if (n.d !== "") {
                if (n.d != null || n.d != undefined) {
                    arr = $.parseJSON(n.d);
                }
            }
        },
        error: function () { }
    });
    return arr;
}
function SelectAllKhoa() {
    var arr = [];
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/SelectAllKhoa",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "",
        async: false,
        success: function (n) {
            if (n.d !== "") {
                if (n.d != null || n.d != undefined) {
                    arr = $.parseJSON(n.d);
                }
            }
        },
        error: function () { }
    });
    return arr;
}
function SelectAllDoiTuongBaoHiem() {
    var arr = [];
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/SelectAllDoiTuongBaoHiem",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "",
        async: false,
        success: function (n) {
            if (n.d !== "") {
                if (n.d != null || n.d != undefined) {
                    arr = $.parseJSON(n.d);
                }
            }
        },
        error: function () { }
    });
    return arr;
}
function SelectAllTaiKhoan() {
    var arr = [];
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/SelectAllTaiKhoan",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "",
        async: false,
        success: function (n) {
            if (n.d !== "") {
                if (n.d != null || n.d != undefined) {
                    arr = $.parseJSON(n.d);
                }
            }
        },
        error: function () { }
    });
    return arr;
}
function SelectAllChucVu() {
    var arr = [];
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/SelectAllChucVu",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "",
        async: false,
        success: function (n) {
            if (n.d !== "") {
                if (n.d != null || n.d != undefined) {
                    arr = $.parseJSON(n.d);
                }
            }
        },
        error: function () { }
    });
    return arr;
}
function SelectVatTuById(mavattu) {
    var arr = [];
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/SelectVatTuById",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "{'mavattu': '" + mavattu + "'}",
        async: false,
        success: function (n) {
            if (n.d !== "") {
                if (n.d != null || n.d != undefined) {
                    arr = $.parseJSON(n.d);
                }
            }
        },
        error: function () { }
    });
    return arr;
}
function SelectVatTuByMaKho(makho) {
    var arr = [];
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/SelectVatTuByMaKho",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "{'makho': '" + makho + "'}",
        async: false,
        success: function (n) {
            if (n.d !== "") {
                if (n.d != null || n.d != undefined) {
                    arr = $.parseJSON(n.d);
                }
            }
        },
        error: function () { }
    });
    return arr;
}
function SelectKhachHangByMaLoaiKhachHang(maloaikhachhang) {
    var arr = [];
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/SelectKhachHangByMaLoaiKhachHang",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "{'maloaikhachhang': '" + maloaikhachhang + "'}",
        async: false,
        success: function (n) {
            if (n.d !== "") {
                if (n.d != null || n.d != undefined) {
                    arr = $.parseJSON(n.d);
                }
            }
        },
        error: function () { }
    });
    return arr;
}
function SelectTaiKhoanById(taikhoan) {
    var arr = [];
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/SelectTaiKhoanById",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "{'id': '" + taikhoan + "'}",
        async: false,
        success: function (n) {
            if (n.d !== "") {
                if (n.d != null || n.d != undefined) {
                    arr = $.parseJSON(n.d);
                }
            }
        },
        error: function () { }
    });
    return arr;
}
function SelectKhoByKhoa(makhoa) {
    var arr = [];
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/SelectKhoByKhoa",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "{'makhoa': '" + makhoa + "'}",
        async: false,
        success: function (n) {
            if (n.d !== "") {
                if (n.d != null || n.d != undefined) {
                    arr = $.parseJSON(n.d);
                }
            }
        },
        error: function () { }
    });
    return arr;
}
function SelectPhongBanByKhoa(makhoa) {
    var arr = [];
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/SelectPhongBanByKhoa",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "{'makhoa': '" + makhoa + "'}",
        async: false,
        success: function (n) {
            if (n.d !== "") {
                if (n.d != null || n.d != undefined) {
                    arr = $.parseJSON(n.d);
                }
            }
        },
        error: function () { }
    });
    return arr;
}
function CheckTon_Ma_Lo_PhieuNhap(mavattu, losanxuat, maphieunhap, makho) {
    var arr = [];
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/CheckTon_Ma_Lo_PhieuNhap",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "{'mavattu': '" + mavattu + "', 'losanxuat': '" + losanxuat + "'" +
            ", 'maphieunhap': '" + maphieunhap + "', 'makho': '" + makho + "'}",
        async: false,
        success: function (n) {
            if (n.d !== "") {
                if (n.d != null || n.d != undefined) {
                    arr = $.parseJSON(n.d);
                }
            }
        },
        error: function () { }
    });
    return (arr.length <= 0 ? "0" : arr[0].SoLuong);
}
function CheckTon_Ma_Lo_PhieuNhap_NotHSD(mavattu, losanxuat, maphieunhap, makho) {
    var arr = [];
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/CheckTon_Ma_Lo_PhieuNhap_NotHSD",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "{'mavattu': '" + mavattu + "', 'losanxuat': '" + losanxuat + "'" +
            ", 'maphieunhap': '" + maphieunhap + "', 'makho': '" + makho + "'}",
        async: false,
        success: function (n) {
            if (n.d !== "") {
                if (n.d != null || n.d != undefined) {
                    arr = $.parseJSON(n.d);
                }
            }
        },
        error: function () { }
    });
    return (arr.length <= 0 ? "0" : arr[0].SoLuong);
}
function CheckTon_MaKho_MaVatTu(makho, mavattu) {
    var arr = [];
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/CheckTon_MaKho_MaVatTu",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "{'makho': '" + makho + "', 'mavattu': '" + mavattu + "'}",
        async: false,
        success: function (n) {
            if (n.d !== "") {
                if (n.d != null || n.d != undefined) {
                    arr = $.parseJSON(n.d);
                }
            }
        },
        error: function () { }
    });
    return (arr.length <= 0 ? "0" : arr[0].SoLuong);
}
function TrangThaiTaiKhoan(taikhoan) {
    var str = "";
    $.ajax({
        type: "POST",
        url: "/Webservice/wsSelectAll.asmx/TrangThaiTaiKhoan",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        beforeSend: function () { },
        data: "{'taikhoan': '" + taikhoan + "'}",
        async: false,
        success: function (n) {
            str = n.d;
        },
        error: function () { }
    });
    return str;
}